//
//  DynamicDetailVC.m
//  TuYouAPP
//
//  Created by L on 14-2-22.
//
//

#import "DynamicDetailVC.h"
#import "DynamicDetailCell.h"
#import "DataModel.h"
#import "DynamicReplyVC.h"
#import "PublishVC.h"
#import "YanTuVC.h"
#import "UIImageView+WebCache.h"
#import "Util.h"
#import "UIButton+WebCache.h"
#import "MyPublishVC.h"
#import "LoginVC.h"
#import "DynamicDetailVC.h"
#import "TishiDynamicDetailVC.h"
#import "JinghuaDynamicDetailVC.h"
@interface DynamicDetailVC ()
{
    NSMutableArray *tempArray;
    UIButton *tempBtn;
    TYUserState *topstate;
    NSDate *lastTime;
    NSDate *firstTime;
    BOOL nowIsNew;
    UIButton *leftbtn;
    UIButton *rightbtn;
}
@end

@implementation DynamicDetailVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillDisappear:(BOOL)animated
{
    rightbtn.hidden = YES;
    leftbtn.hidden = YES;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navBar.titleLabel.hidden = YES;
    rightbtn.hidden = NO;
    leftbtn.hidden = NO;
    self.Title = @"最新动态";
}

-(void)topViewTouched:(UIGestureRecognizer *)ges
{
    DynamicReplyVC *vc = [[DynamicReplyVC alloc]init];
    vc.thePublish = _topUserState;
    [self.navigationController pushViewController:vc animated:YES];

}
-(void)loadTitleBtn
{
    if (SystemIsiOS7()) {

       leftbtn = [[UIButton alloc]initWithFrame:CGRectMake(75, 28, 85, 28)];
        [leftbtn setBackgroundImage:[UIImage imageNamed:@"zuo-dianji.png"] forState:UIControlStateNormal];
        [leftbtn setTitle:@"前方" forState:UIControlStateNormal];
        leftbtn.adjustsImageWhenHighlighted = NO;
        [leftbtn addTarget:self action:@selector(leftTitleBtnTouched) forControlEvents:UIControlEventTouchUpInside];
        [leftbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        rightbtn = [[UIButton alloc]initWithFrame:CGRectMake(160, 28, 85, 28)];
        [rightbtn setBackgroundImage:[UIImage imageNamed:@"you.png"] forState:UIControlStateNormal];
        [rightbtn addTarget:self action:@selector(rightBtnBtnTouched) forControlEvents:UIControlEventTouchUpInside];
         [rightbtn setTitle:@"全部" forState:UIControlStateNormal];
        rightbtn.adjustsImageWhenHighlighted = NO;
        
        [rightbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.navBar addSubview:leftbtn];
        [self.navBar addSubview:rightbtn];
    }
    else
    {
        leftbtn = [[UIButton alloc]initWithFrame:CGRectMake(75, 8, 85, 28)];
        [leftbtn setBackgroundImage:[UIImage imageNamed:@"zuo-dianji.png"] forState:UIControlStateNormal];
        [leftbtn setTitle:@"前方" forState:UIControlStateNormal];
        leftbtn.adjustsImageWhenHighlighted = NO;
        [leftbtn addTarget:self action:@selector(leftTitleBtnTouched) forControlEvents:UIControlEventTouchUpInside];
        [leftbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        rightbtn = [[UIButton alloc]initWithFrame:CGRectMake(160, 8, 85, 28)];
        [rightbtn setBackgroundImage:[UIImage imageNamed:@"you.png"] forState:UIControlStateNormal];
        [rightbtn addTarget:self action:@selector(rightBtnBtnTouched) forControlEvents:UIControlEventTouchUpInside];
        [rightbtn setTitle:@"全部" forState:UIControlStateNormal];
        rightbtn.adjustsImageWhenHighlighted = NO;
        
        [rightbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.navBar addSubview:leftbtn];
        [self.navBar addSubview:rightbtn];
    }
}
-(void)leftTitleBtnTouched
{
    [leftbtn setBackgroundImage:[UIImage imageNamed:@"zuo-dianji.png"] forState:UIControlStateNormal];
    [leftbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightbtn setBackgroundImage:[UIImage imageNamed:@"you.png"] forState:UIControlStateNormal];
    [rightbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
-(void)rightBtnBtnTouched
{
    [leftbtn setBackgroundImage:[UIImage imageNamed:@"zuo.png"] forState:UIControlStateNormal];
    [leftbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightbtn setBackgroundImage:[UIImage imageNamed:@"you-dianji.png"] forState:UIControlStateNormal];
    [rightbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
}
- (void)viewDidLoad
{
    self.mPageName = @"线路详情";

    [super viewDidLoad];
    [self loadTitleBtn];
    self.LeftBarTitle = @"返回";
    self.RightBarTitle = @"发布";
    tempArray = [[NSMutableArray alloc]init];
    [SVProgressHUD showWithStatus:@"加载中"];
    self.page = 1;
    [TYUtil updateUserPoint];
    
    [_mTagLine getNewestStateOfTheLineByTime:nil bback:YES callback:^(NSArray *all, NSString *err) {
      //
        nowIsNew = YES;
        if (!err &&all) {
            [SVProgressHUD dismiss];
            [tempArray addObjectsFromArray:all];
            TYUserState *state = [all firstObject];
            firstTime = state.mTimeC;
            state = [all lastObject];
            lastTime = state.mTimeC;
            [self.tableview reloadData];
            self.tableview.tableFooterView.hidden = NO;
            if (tempArray.count < ONE_PAGE) {
                self.refreshLabel.text = self.textNoMore;
            }

        }
        
     else
     {
         
         [SVProgressHUD showErrorWithStatus:err];
     }

    }];
    
    
//    [_mTagLine getNewestStateOfTheLine:self.page callback:^(NSArray *all, NSString *err) {
//        
//        [SVProgressHUD dismiss];
//        if( all )
//        {
//          
//            self.page ++;
//            [tempArray addObjectsFromArray:all];
//            TYUserState *state = [all firstObject];
//            firstTime = state.mTimeC;
//            state = [all lastObject];
//            lastTime = state.mTimeC;
//            [self.tableview reloadData];
//            self.tableview.tableFooterView.hidden = NO;
//            if (tempArray.count < ONE_PAGE) {
//                self.refreshLabel.text = self.textNoMore;
//            }
//        }
//        else
//        {
//                
//            [SVProgressHUD showErrorWithStatus:err];
//        }
//        
//    }];
     	// Do any additional setup after loading the view.
    self.haveFullupRefreshView = YES;
    [self initWithRefreshTableViewIos7:CGRectMake(0, 64, 320, DEVICE_Height-64) Ios6rect:CGRectMake(0, 44, 320, DEVICE_Height-64)];
    self.tableview.tableFooterView.hidden = YES;
    
        if (_topUserState) {
            UIView *topView = nil;
            if( _topUserState.mContext!= nil && _topUserState.mContext.length > 0 )
            {
                topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 90)];
                topView.backgroundColor = [UIColor clearColor];
                
                
                NSMutableString *mstr = [[NSMutableString alloc]initWithFormat:@"@%@:",_topUserState.mTaguser.mUserDisplayName];
                
                [mstr appendString:_topUserState.mContext];
                
           
                NSMutableAttributedString *str =[[NSMutableAttributedString alloc] initWithString:mstr];
                int l = _topUserState.mTaguser.mUserDisplayName.length;
                [str addAttribute:NSForegroundColorAttributeName value:ColorRGB(205, 136, 52) range:NSMakeRange(0,l+1)];
                //  [attString addAttribute:<#(NSString *)#> value:<#(id)#> range:<#(NSRange)#>]
                
                NSInteger strLength = [str length];
                NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
                [style setLineSpacing:2];
                [str addAttribute:NSParagraphStyleAttributeName
                                  value:style
                                  range:NSMakeRange(0, strLength)];
                
                CGSize constraint = CGSizeMake(295, CGFLOAT_MAX);
                CGSize size = [[str string] sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
                UILabel *timelabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 15, 250, 20)];
                timelabel.text =[Util FormartTime:_topUserState.mTimeC bfull:NO];
                timelabel.numberOfLines = 0;
                timelabel.textColor =[UIColor grayColor];
                //    topLabel.textColor = [UIColor blackColor];
                timelabel.backgroundColor = [UIColor clearColor];
                timelabel.font = [UIFont systemFontOfSize:14];
                UILabel *topLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 35, 295, size.height+15)];
                topLabel.attributedText = str;
                topLabel.numberOfLines = 0;
                //    topLabel.textColor = [UIColor blackColor];
                topLabel.backgroundColor = [UIColor clearColor];
                topLabel.font = [UIFont systemFontOfSize:16];
                
       
                UIImageView *bgview = [[UIImageView alloc]initWithFrame:CGRectMake(6, 10, 306, topLabel.frame.size.height+topLabel.frame.origin.y)];
                
                CGRect rect = topView.frame;
                rect.size.height = bgview.frame.size.height+12;
                topView.frame = rect;
                bgview.backgroundColor = [UIColor whiteColor];
                bgview.layer.borderWidth = 0.5;
                bgview.layer.borderColor = [ColorRGB(212, 212, 212)CGColor];
                [topView addSubview:bgview];
                [topView addSubview:topLabel];
                [topView addSubview:timelabel];

                UIImageView *closeimage = [[UIImageView alloc]initWithFrame:CGRectMake(288, 16, 17, 17)];
                //UIImageView.titleLabel.font = [UIFont systemFontOfSize:16];
                
                UIButton *closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(260, 14, 50, 25)];
             closeBtn.backgroundColor = [UIColor clearColor];

               closeimage.image = [UIImage imageNamed:@"ClearButtonBG.png"];
//              //  [closeBtn setTitle:@"关闭" forState:UIControlStateNormal];
                [closeBtn addTarget:self action:@selector(closeBtnTouched:) forControlEvents:UIControlEventTouchUpInside];
                [topView addSubview:closeimage];
                [topView addSubview:closeBtn];
                UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc ]initWithTarget:self action:@selector(topViewTouched:)];
                [topView addGestureRecognizer:tap];
                
            }
            self.tableview.tableHeaderView = topView;

        }
    
   
    self.tableview.backgroundColor = ColorRGB(230, 230, 230);
    self.tableview.separatorStyle = UITableViewCellEditingStyleNone;
    
//    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 48)];
//    footerView.backgroundColor =[UIColor clearColor];
//    self.tableview.tableFooterView = footerView;
    
    UIView *botBarView;
    if (SystemIsiOS7()) {
        botBarView  = [[UIView alloc]initWithFrame:CGRectMake(0, DEVICE_Height-48, 320, 48)];

    }
    else
    {
           botBarView  = [[UIView alloc]initWithFrame:CGRectMake(0, DEVICE_Height-68, 320, 48)];
    }
    UIImageView *botbg = [[UIImageView alloc]initWithFrame:botBarView.bounds];
    botbg.image = [UIImage imageNamed:@"dibubeijing.png"];
    [botBarView addSubview:botbg];
    

    float x = 0.0f;
    for (int i = 0; i<4; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(x, 0, 80, 48)] ;
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(x+28, 3, 24, 24)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(x+28, 28, 30, 20)];
        btn.tag =10+i;
        image.tag = 20+i;
        label.tag = 30+i;
        
        [btn addTarget:self action:@selector(tabBarBtnTouched:) forControlEvents:UIControlEventTouchUpInside];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = ColorRGB(137, 137, 137);
        label.font = [UIFont boldSystemFontOfSize:12];
        if (i == 0) {
            image .image = [UIImage imageNamed:@"zuixin-xuanzhong.png"];
            label.text = @"最新";
            label.textColor = [UIColor whiteColor];
            tempBtn = btn;
        }
        else if (i == 1)
        {
     
            image .image = [UIImage imageNamed:@"tishi_hui.png"];
            label.text = @"提示";

        }
        else if (i==2)
        {
            image .image = [UIImage imageNamed:@"jinghua.png"];
            label.text = @"精华";
        }
        else
        {
            image .image = [UIImage imageNamed:@"yantu.png"];
            label.text = @"沿途";
        }
       // [btn setBackgroundColor:[UIColor redColor]];
        [botBarView addSubview:btn];
        [botBarView addSubview:label];
        [botBarView addSubview:image];
        x+= 80;
    }
  
   // botBarView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:botBarView];
}
-(void)closeBtnTouched:(id)sender
{

    [UIView animateWithDuration:0.3 animations:^{
        self.tableview.tableHeaderView  = nil;

    } completion:^(BOOL finished) {
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[NSNumber numberWithBool:YES] forKey:self.topUserState.objId];
    }];
    
}
-(void)tabBarBtnTouched:(UIButton *)sender
{
    if (tempBtn == sender ) {
        if (sender.tag == 13) {
            YanTuVC *vc = [[YanTuVC alloc]initWithNibName:@"YanTuVC" bundle:nil];
            [self.navigationController pushViewController:vc animated:YES];
        }
        return;
    }
    int tag = sender.tag-10;
//        UIView *aview = sender.superview;
    if (tag == 0) {

        
//        UIImageView *image = (UIImageView*)[aview viewWithTag:tag+20];
//        image.image = [UIImage imageNamed:@"tishi_lan_2.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:tag+30];
//        label.textColor = [UIColor whiteColor];
        //提示
       
    }
    else if (tag == 1)
    {
        
//        [Util updateUserPoint];
//
//        UIImageView *image = (UIImageView*)[aview viewWithTag:tag+20];
//        image.image = [UIImage imageNamed:@"zuixin-xuanzhong.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:tag+30];
//        label.textColor = [UIColor whiteColor];
//        //最新
//        [SVProgressHUD showWithStatus:@"加载中"];
//        [_mTagLine getNewestStateOfTheLineByTime:nil bback:YES callback:^(NSArray *all, NSString *err) {
//            //
//            
//            nowIsNew = YES;
//            if (!err &&all) {
//                
//                if (all.count <ONE_PAGE) {
//                    self.refreshLabel.text = self.textNoMore;
//                    
//                }
//                else
//                {
//                    self.refreshLabel.text = self.textPull;
//                    
//                }
//
//                [SVProgressHUD dismiss];
//                [tempArray removeAllObjects];
//                [tempArray addObjectsFromArray:all];
//                TYUserState *state = [all firstObject];
//                firstTime = state.mTimeC;
//                state = [all lastObject];
//                lastTime = state.mTimeC;
//                [self.tableview reloadData];
//                [self.tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
//                self.tableview.tableFooterView.hidden = NO;
//                if (tempArray.count < ONE_PAGE) {
//                    self.refreshLabel.text = self.textNoMore;
//                }
//                [SVProgressHUD showSuccessWithStatus:@"加载成功"];
//            }
//            
//            else
//            {
//                
//                [SVProgressHUD showErrorWithStatus:err];
//            }
//            
//        }];
        TishiDynamicDetailVC *vc = [[TishiDynamicDetailVC alloc]init];
        vc.mTagLine = self.mTagLine;
        vc.lineTitle = self.lineTitle;
        [self.navigationController pushViewController:vc animated:YES];

        
        
    }
    else if (tag == 2)
    {
        JinghuaDynamicDetailVC *vc = [[JinghuaDynamicDetailVC alloc]init];
        vc.mTagLine = self.mTagLine;
        vc.lineTitle = self.lineTitle;
//        NSMutableArray *array = [[NSMutableArray alloc]init];
//        [array addObjectsFromArray: self.navigationController.viewControllers];
//        
//        [array removeLastObject];
//        [array addObject:vc];
        
        
//        CATransition *animation = [CATransition animation];
//        //动画时间
//        animation.duration = 0.5f;
//        //先慢后快
////        animation.timingFunction = UIViewAnimationCurveEaseInOut;
////        animation.fillMode = kCAFillModeForwards;
//        animation.type  =kCATransitionFade;
//        [self.view.layer addAnimation:animation forKey:@"animation"];

        [self.navigationController pushViewController:vc animated:YES];
//        UIImageView *image = (UIImageView*)[aview viewWithTag:tag+20];
//        image.image = [UIImage imageNamed:@"jinghua-xuanzhong.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:tag+30];
//        label.textColor = [UIColor whiteColor];
//        
//        [SVProgressHUD showWithStatus:@"加载中"];
//        self.page =1;
//        [_mTagLine getBestStatesOfTheLineByTime:self.page bback:YES callback:^(NSArray *all, NSString *err) {
//            if (all &&!err) {
//                if (all.count == 0) {
//                    [SVProgressHUD dismiss];
//                    self.refreshLabel.text = self.textNoMore;
//                     [tempArray removeAllObjects];
//                    [self.tableview reloadData];
//
//                    return ;
//                }
//                if (all.count <ONE_PAGE) {
//                    self.refreshLabel.text = self.textNoMore;
//
//                }
//                else
//                {
//                    self.refreshLabel.text = self.textPull;
//
//                }
//                nowIsNew = NO;
//                self.page++;
//                [SVProgressHUD showSuccessWithStatus:@"加载成功"];
//                [tempArray removeAllObjects];
//                [tempArray addObjectsFromArray:all];
//                [self.tableview reloadData];
//                [self.tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
//            }
//            else
//            {
//                [SVProgressHUD showErrorWithStatus:@"加载失败"];
//            }
//        }];
     //精华
    }
    else if (tag == 3)
    {
//        [Util updateUserPoint];
//        
//        UIImageView *image = (UIImageView*)[aview viewWithTag:tag+20];
//        image.image = [UIImage imageNamed:@"yantu-xuanzhong.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:tag+30];
//        label.textColor = [UIColor whiteColor];
        YanTuVC *vc = [[YanTuVC alloc]init];
        
//        NSMutableArray *array = [[NSMutableArray alloc]init];
//        [array addObjectsFromArray: self.navigationController.viewControllers];
//        
//        [array removeLastObject];
//        [array addObject:vc];
        [self.navigationController pushViewController:vc animated:YES];
      //  [self.navigationController setViewControllers:array animated:NO];
        
    }
    
//    
//    int oldTag = tempBtn.tag-10;
//    
//    if (oldTag == 0) {
//        UIImageView *image = (UIImageView*)[aview viewWithTag:oldTag+20];
//        image.image = [UIImage imageNamed:@"tishi_hui.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:oldTag+30];
//        label.textColor = ColorRGB(137, 137, 137);
//    }
//    else if (oldTag == 1)
//    {
//        UIImageView *image = (UIImageView*)[aview viewWithTag:oldTag+20];
//        image.image = [UIImage imageNamed:@"zuixin.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:oldTag+30];
//        label.textColor = ColorRGB(137, 137, 137);
//    }
//    else if (oldTag == 2)
//    {
//        UIImageView *image = (UIImageView*)[aview viewWithTag:oldTag+20];
//        image.image = [UIImage imageNamed:@"jinghua.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:oldTag+30];
//        label.textColor = ColorRGB(137, 137, 137);
//    }
//    else if (oldTag == 3)
//    {
//        UIImageView *image = (UIImageView*)[aview viewWithTag:oldTag+20];
//        image.image = [UIImage imageNamed:@"yantu.png"];
//        UILabel *label = (UILabel *)[aview viewWithTag:oldTag+30];
//        label.textColor = ColorRGB(137, 137, 137);
//    }
//    tempBtn = sender;

}

- (void)pushViewController: (UIViewController*)controller
    animatedWithTransition: (UIViewAnimationTransition)transition {
    
    CATransition *animation = [CATransition animation];
    //动画时间
    animation.duration = 0.5f;
    //先慢后快
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    [self.view.layer addAnimation:animation forKey:@"animation"];
    //animation.removedOnCompletion = NO;
    [self.navigationController pushViewController:controller animated:NO];
    
//    [UIView beginAnimations:nil context:nil];
//    
//    [UIView setAnimationDuration:0.3];
//    [UIView setAnimationDelegate:self];
//   // [UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
//    [UIView setAnimationTransition:transition forView:self.view cache:YES];
//    [UIView commitAnimations];
}
-(void)leftBtnTouched:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)rightBtnTouched:(id)sender{
    PublishVC *vc = [[PublishVC alloc]init];
    vc.comeFrom = 2;
    if ([TYUser isNeedLogin]) {
        LoginVC *logvc = [[LoginVC alloc]initWithNibName:@"LoginVC" bundle:nil];
        logvc.tagVC = vc;
        [self.navigationController pushViewController:logvc animated:YES];
        return;

    }
    [self.navigationController pushViewController:vc animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tempArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CustomCellIdentifier = @"DynamicDetailCell";
    
    DynamicDetailCell *cell = (DynamicDetailCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];

    BOOL isUsed = NO;
    if (!isUsed &&! cell) {
        UINib *nib = [UINib nibWithNibName:@"DynamicDetail" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:@"DynamicDetailCell"];
       // isUsed = YES;
        cell = (DynamicDetailCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];

    }
    
    TYUserState* publish = [tempArray objectAtIndex:indexPath.row];
    
 //   [self.tableview reloadData];
    if (publish.mImgArr.count == 0 ||publish.mImgArr == nil) {
        for (int j =0; j<9; j++) {
            UIImageView *image = (UIImageView *)[cell viewWithTag:10+j];
            image.hidden = YES;

        }
    }
        else
        {
    for (int i = 0; i<publish.mImgArr.count; i++) {
        for (int j =0; j<9; j++) {
           UIImageView *image = (UIImageView *)[cell viewWithTag:10+j];

            if (j< publish.mImgArr.count) {
                
                image.hidden = NO;
                //image.image = [publish.mImgArr objectAtIndex:j];
                
                NSString* ts = [publish.mImgArr objectAtIndex:j];
                if( ts )
                {
                    NSURL* turl  = [NSURL URLWithString:[Util makeSmallImgURL:ts]];
                    //NSLog(@"imgurl:%@",turl);
                    [image setImageWithURL: turl placeholderImage:S_D_IMG options:SDWebImageProgressiveDownload];
                 //   [image setImageWithURL:turl];
                   //[image setImageWithURL:turl placeholderImage:S_D_IMG];
            
                    
                }
                else
                {
                    image.image = S_D_IMG;
                }
            }
            else
            {
                image.hidden = YES;
            }
                        //  image.image = [UIImage imageNamed:str];
            
                }
            }
        }
    
    [cell upDateCell:publish];
    
   cell.bgImage.layer.borderWidth = 0.5;
   cell.bgImage.layer.borderColor = [ColorRGB(212, 212, 212)CGColor];
    if ( publish.mTaguser.mSex == 2) {
        cell.sexImage.image = [UIImage imageNamed:@"men.png"];
    }
    else
    {
        cell.sexImage.image = [UIImage imageNamed:@"women.png"];

    }
    cell.AddrDistance.text = publish.mPBetweenInfo;
    cell.userAddr .text = publish.mPointInfo;
    if (publish.mPointInfo.length == 0) {
        cell.addrImgae.hidden = YES;
    }
    else
    {
        cell.addrImgae.hidden = NO;
    }

    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc]initWithString:publish.mContext];
    NSInteger strLength = [publish.mContext length];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineSpacing:2];
    [attString addAttribute:NSParagraphStyleAttributeName
                      value:style
                      range:NSMakeRange(0, strLength)];
    
    [cell.headImage setBackgroundImageWithURL:[NSURL URLWithString:publish.mTaguser.mHeadImgURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"70_70.png"]];
    [cell.topBtn addTarget:self action:@selector(headImageBtnTouched:) forControlEvents:UIControlEventTouchUpInside];
    cell.UserContent.attributedText = attString;
    
    cell.userPublishTime.text = [Util FormartTime:publish.mTimeC bfull:NO];
    cell.userName.text = publish.mTaguser.mUserDisplayName;
    cell.reBackCountLab.text =publish.mReBackCount>0? [NSString stringWithFormat:@"%d条回复",publish.mReBackCount]:@"暂无回复";

    cell.styleIconImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"style_icon_%d.png",publish.mStyle]];
    cell.nodeNameLab.text = publish.mRelInfo;
   // cell.selectionStyle = UITableViewCellSelectionStyleNone;
    // cell.textLabel.text = @"success";
    return cell;


}
-(void)headImageBtnTouched:(UIButton *)sender
{
    DynamicDetailCell *cell = (DynamicDetailCell*)sender.superview.superview.superview.superview;
    NSIndexPath *indexpath = [self.tableview indexPathForCell:cell];

    TYUserState *comment = [tempArray objectAtIndex:indexpath.row];
    MyPublishVC *vc = [[MyPublishVC alloc]init];
    vc.fromMyself = NO;
    vc.user =comment.mTaguser;
    [self.navigationController pushViewController:vc animated:YES];
    NSLog(@"%D",indexpath.row);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DynamicReplyVC *vc = [[DynamicReplyVC alloc]init];
    vc.isFromHis = NO;
    vc.thePublish = [tempArray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    DynamicDetailVC *vc = [[DynamicDetailVC alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
    
}
-(void)refresh
{
//    [_mTagLine getNewestStateOfTheLine:self.page callback:^(NSArray *all, NSString *err) {
//        
//        [SVProgressHUD dismiss];
//        if( all )
//        {
//            
//            self.page ++;
//            [tempArray addObjectsFromArray:all];
//            [self.tableview reloadData];
//           // self.tableview.tableFooterView.hidden = NO;
//            [self stopLoading];
//            if (all.count < ONE_PAGE) {
//                self.refreshLabel.text = self.textNoMore;
//                [SVProgressHUD showErrorWithStatus:@"没有更多数据"];
//            }
//        }
//        else
//        {
//            
//            [SVProgressHUD showErrorWithStatus:err];
//        }
//
//    }];

//    if (nowIsNew) {
    
    [_mTagLine getNewestStateOfTheLineByTime:lastTime bback:NO callback:^(NSArray *all, NSString *err) {
        [SVProgressHUD dismiss];
         [self stopLoading];
        if( all )
        {
            [SVProgressHUD dismiss];
            if (all.count == 0) {
                self.refreshLabel.text = self.textNoMore;
              //  [SVProgressHUD showErrorWithStatus:@"没有更多数据"];
                [self.tableview reloadData];
            
                return ;
            }
            TYUserState *state = [all firstObject];
            firstTime = state.mTimeC;
            state = [all lastObject];
            lastTime = state.mTimeC;
            
            NSRange range = NSMakeRange(tempArray.count, [all count]);
            [tempArray insertObjects:all atIndexes: [NSIndexSet indexSetWithIndexesInRange:range]];
            [self.tableview reloadData];
            // self.tableview.tableFooterView.hidden = NO;
            [self stopLoading];
            if (all.count < ONE_PAGE) {
                self.refreshLabel.text = self.textNoMore;
              //  [SVProgressHUD showErrorWithStatus:@"没有更多数据"];
            }
            else
            {
                   self.refreshLabel.text = self.textPull;
            }
        }
        else
        {
            
            [SVProgressHUD showErrorWithStatus:err];
        }

    }];
// }
//    
//    else
//    {
//        
//
//        [_mTagLine getBestStatesOfTheLineByTime:self.page bback:NO callback:^(NSArray *all, NSString *err) {
//            
//            [self stopLoading];
//
//            if (all &&!err) {
//                nowIsNew = NO;
//              //  [SVProgressHUD showSuccessWithStatus:@"加载成功"];
//               // [tempArray removeAllObjects];
//                [tempArray addObjectsFromArray:all];
//                [self.tableview reloadData];
//                if (all.count <ONE_PAGE) {
//                    self.refreshLabel.text = self.textNoMore;
//                  //  [SVProgressHUD showErrorWithStatus:@"没有更多数据"];
//                    self.page++;
//                    
//                    return ;
//                }
//                else
//                {
//                    self.refreshLabel.text = self.textPull;
//                }
//                self.page++;
//
//            }
//            else
//            {
//                [SVProgressHUD showErrorWithStatus:@"加载失败"];
//            }
//        }];
//
//    }
}

- (void)slimeRefreshStartRefresh:(SRRefreshView *)refreshView
{
    //
    
    //    self.page = 1;
    //    [_mTagLine getNewestStateOfTheLine:self.page callback:^(NSArray *all, NSString *err) {
    //        [self.slimeView endRefresh];
    //        [SVProgressHUD dismiss];
    //        if( all )
    //        {
    //            tempArray = [[NSMutableArray alloc]init];
    //            self.page++;
    //            [SVProgressHUD showSuccessWithStatus:@"刷新成功"];
    //            [tempArray addObjectsFromArray:all];
    //            [self.tableview reloadData];
    //        }
    //        else
    //        {
    //
    //            [SVProgressHUD showErrorWithStatus:err];
    //        }
    //
    //    }];

        
 
    [_mTagLine getNewestStateOfTheLineByTime:firstTime bback:YES callback:^(NSArray *all, NSString *err) {
        [SVProgressHUD dismiss];
         [self.slimeView endRefresh];
        if( all )
        {
            [SVProgressHUD dismiss];

            if (all.count == 0) {
                self.refreshLabel.text = self.textNoMore;
            
              //  [self.tableview reloadData];
                return ;
            }
            TYUserState *state = [all firstObject];
            firstTime = state.mTimeC;
            state = [all lastObject];
            lastTime = state.mTimeC;
            
            NSRange range = NSMakeRange(0, all.count);
            [tempArray insertObjects:all atIndexes: [NSIndexSet indexSetWithIndexesInRange:range]];
            [self.tableview reloadData];
            // self.tableview.tableFooterView.hidden = NO;
            [self stopLoading];
            if (all.count < ONE_PAGE) {
               self.refreshLabel.text = self.textNoMore;
            }
            else
            {
                self.refreshLabel.text = self.textPull;

            }
        }
        else
        {
            
            [SVProgressHUD showErrorWithStatus:err];
        }
        
    }];
    
//    else
//    {
//        [Util updateUserPoint];
//
//        self.page=1;
//        [_mTagLine getBestStatesOfTheLineByTime:self.page bback:YES callback:^(NSArray *all, NSString *err) {
//            [self.slimeView endRefresh];
//
//
//            if (all &&!err) {
//                [SVProgressHUD dismiss];
//                self.page++;
//                nowIsNew = NO;
//                tempArray = [[NSMutableArray alloc]init];
//             //   [tempArray removeAllObjects];
//                [tempArray addObjectsFromArray:all];
//                [self.tableview reloadData];
//            }
//            else
//            {
//                [SVProgressHUD showErrorWithStatus:@"加载失败"];
//            }
//        }];
//
//    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
